<template>
  <div class="login-parent" :style="{ height: bodyHeight + 'px' }">
    <van-icon name="arrow-left" size="20" color="#ffffff" class="back" @click="$router.back()"/>
    <div class="logo-wrap">
      <img class="web-logo" :src="require('@/assets/images/logo.jpg')"/>
    </div>
    <div class="login-form">

      <div class="input-wrap">
        <van-icon name="manager" color="#eeeeee" size="20"/>
        <input type="text" name="username" v-model="form.username" placeholder="请输入用户名"/>
      </div>
      <div class="input-wrap">
        <van-icon name="lock" color="#eeeeee" size="20"/>
        <input type="password" name="password" v-model="form.password" placeholder="请输入密码"/>
      </div>
      <div class="button-wrap">
        <van-button round size="small" class="login-button" @click="onSubmit">登录</van-button>
        <router-link class="link regist-button login-button" to="register">注册</router-link>
      </div>
      <p class="forget-password">
        <router-link class="link" to="register">忘记密码</router-link>
      </p>
    </div>

  </div>
</template>

<script>
import {authLoginByAccount} from '../../api/user'
import {Toast} from 'vant'
import {setLocalStorage} from '../../utils/local-storage'

export default {
  name: 'login',
  mounted () {
    this.bodyHeight = document.documentElement.clientHeight
  },
  data () {
    return {
      bodyHeight: 0,
      form: {}
    }
  },
  methods: {
    routerRedirect () {
      // const { query } = this.$route;
      // this.$router.replace({
      //   name: query.redirect || 'home',
      //   query: query
      // });
      window.location = '/user/'
    },

    onSubmit () {
      authLoginByAccount(this.form).then(res => {
        let userInfo = res.data.data.userInfo
        console.log('----res-------')
        setLocalStorage({
          Authorization: res.data.data.token,
          avatar: userInfo.avatarUrl,
          nickName: userInfo.nickName,
          sign: userInfo.sign
        })
        this.routerRedirect()
      }).catch(error => {
        Toast.fail(error.data.errmsg)
      })
    },
    handleSize () {

    }
  }
}
</script>

<style scoped>

.button-wrap {
  margin-top: 2rem;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  align-items: center;
}

.login-button {
  color: #E65D6E;
  padding: 1rem 4rem;
}

.back {
  padding: 10px;
}

.regist-button {
  font-size: 12px;
  border: none;
  background-color: rgba(255, 255, 255, 0);
  color: white;
}

.web-logo {
  object-fit: contain;
  box-shadow: 1px 1px 1px rgb(240, 240, 240), -1px 1px 1px rgb(240, 240, 240);
  width: 60px;
  height: 60px;
  border-radius: 10px;
  overflow: hidden;
}

.link {
  color: white;
  text-decoration: none;
}

.logo-wrap {
  overflow: auto;
  padding-top: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.login-form {
  padding: 0 20px;
  margin-top: 10px;
}

.login-btutton {
  margin-bottom: 40px;
  margin-top: 40px;
}

.login-parent {
  flex: 1;
  height: 100%;
  background: linear-gradient(to bottom, #ff6034, #E65D6E);
}

.input-wrap {
  border-bottom: 1px #eeeeee solid;
}

input {
  caret-color: red;
  color: white;
  font-size: 16px;
  margin-top: 5rem;
  background-color: rgba(255, 255, 255, 0);
  /*border-color: #c5c5c5;*/
  border-style: solid;
  border-top-width: 0px;
  border-right-width: 0px;
  border-bottom-width: 0px;
  border-left-width: 0px;

}

input:focus {
  padding-bottom: 3px;
  font-size: 18px;
}

.forget-password {
  text-align: right;
  margin-top: 2rem;
  font-size: 12px;
  color: #FFFFFF;
}

input::-webkit-input-placeholder {
  /* WebKit browsers */
  color: white;
}

input:-moz-placeholder {
  /* Mozilla Firefox 4 to 18 */
  color: white;
}

input::-moz-placeholder {
  /* Mozilla Firefox 19+ */
  color: white;
}

input:-ms-input-placeholder {
  /* Internet Explorer 10+ */
  color: white;
}

</style>
